<%@ page pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ page trimDirectiveWhitespaces="true" %>
<fmt:setLocale value="zh_CN"/>

<!--  模板table,模板中不能初始化 -->
<select name="dataType" class="required ignore mysql_dbcolumntype">
	<optgroup label="字符">
		<option value="varchar">varchar</option>
		<option value="text">text</option>
		<option value="char">char</option>
		<option value="mediumtext">mediumtext</option>
	</optgroup>
	<optgroup label="数字">
		<option value="bigint">bigint</option>
		<option value="tinyint">tinyint</option>
		<option value="decimal">decimal</option>
		<option value="double">double</option>
		<option value="mediumint">smallint</option>
		<option value="mediumint">mediumint</option>
		<option value="mediumint">float</option>
	</optgroup>
	<optgroup label="时间">
		<option value="date">date</option>
		<option value="datetime">datetime</option>
		<option value="timestamp">timestamp</option>
		<option value="time">time</option>
		<option value="year">year</option>
	</optgroup>
	<option value="json">json</option>
</select>
<script>
	$(".dbcolumntype").html($(".mysql_dbcolumntype").html());
	$(":input[name=dataType]").filter("select").each(function(){
		var $this = $(this);
		$this.find("option").eq(0).prop("selected", true);
	});
	$(":input[name=dataType]").filter(function(){
		return $(this).val()=="number";
	}).each(function(){
		var $this = $(this);
		$this.val("bigint");
		$this.closest("tr").find("[name='datasize']").val("");
	});
	$(":input[name=dataType]").filter(function(){
		return $(this).val()=="date";
	}).each(function(){
		var $this = $(this);
		$this.val("timestamp");
		$this.closest("tr").find("[name='datasize']").val("");
	});
	$(":input[name=dataType]").filter(function(){
		return $(this).val()=="varchar2";
	}).each(function(){
		var $this = $(this);
		$this.val("varchar");
	});
	// 默认值处理
	$(":input[name=default]").filter(function(){
		return $(this).val();
	}).each(function(){
		var $this = $(this);
		var dataType = $this.closest("tr").find("[name='dataType']").val();
		if(dataType == "timestamp" || dataType == "date" || dataType == "datetime"){
			$this.val("CURRENT_TIMESTAMP");
		}
	});
</script>
